package com.gxa.community.agent.controller;
import com.gxa.community.agent.service.UserService;
import com.gxa.community.core.utils.R;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@Log4j2
//@Validated
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/loginOut")
    public R loginOut(HttpServletRequest request){
        String token = request.getHeader("token");
        if (ObjectUtils.isEmpty(token))
            return R.error("token 异常");
        return userService.loginOut(token);
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public R getUserInfo(HttpServletRequest request) {
        String token = request.getHeader("token");

        if (ObjectUtils.isEmpty(token))
            return R.error("获取失败");

        return userService.getUserInfo(token);
    }
}
